//
// Created by lujun on 19-6-28.
//
// This contains SIN_COS , clarke, inv_clarke, park, inv_park and pid
// each one has it's own function.
// All function can be found in main function.
// If you don't want to use it, then comment it.
#include "../common.h"
#include "riscv_common_tables.h"
#include "riscv_const_structs.h"
#include "riscv_math.h"
#include <stdint.h>

#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"

#include <stdio.h>
#define DELTAF32 (0.05f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)
#define RISCV_MATH_LOOPUNROLL
int test_flag_error = 0;

uint32_t fftSize = 1024;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;

static int DSP_dct4_f32(void)
{
    uint16_t i;
    /* clang-format off */
    float32_t f32_state[256] = {0};
    float32_t dct4_testinput_f32_50hz_200Hz[256] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559};
    float32_t dct4_testinput_f32_50hz_200Hz_ref[256] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559};
    fftSize = 128;
    riscv_cfft_radix4_instance_f32 S;
    uint8_t ifftFlag = 0, doBitReverse = 1;
    /* clang-format on */
    riscv_cfft_radix4_init_f32(&S, 64, ifftFlag, doBitReverse);
    riscv_rfft_instance_f32 SS;
    ifftFlag = 0;
    doBitReverse = 1;
    riscv_rfft_init_f32(&SS, &S, fftSize, ifftFlag, doBitReverse);
    riscv_dct4_instance_f32 SSS = {128, 64, 0.125, Weights_128, cos_factors_128,
                                 &SS, &S};
    BENCH_START(riscv_dct4_f32);
    riscv_dct4_f32(&SSS, f32_state, dct4_testinput_f32_50hz_200Hz);
    BENCH_END(riscv_dct4_f32);
    // ref_dct4_f32(&SSS, f32_state, dct4_testinput_f32_50hz_200Hz_ref);
    float32_t resault, resault_ref;
    uint32_t index, index_ref = 5;
    riscv_max_f32(dct4_testinput_f32_50hz_200Hz, 128, &resault, &index);
    // riscv_max_f32(dct4_testinput_f32_50hz_200Hz_ref,128,&resault_ref,&index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_dct4_f32);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_dct4_f32);
}
static int DSP_dct4_q31(void)
{
    uint16_t i;
    /* clang-format off */
    q31_t q31_state[256] = {0};
    float32_t dct4_testinput_f32_50hz_200Hz[256] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559};
    float32_t dct4_testinput_f32_50hz_200Hz_ref[256] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559};

    q31_t dct4_testinput_q31_50hz_200Hz[256], dct4_testinput_q31_50hz_200Hz_ref[256];
    /* clang-format on */
    riscv_float_to_q31(dct4_testinput_f32_50hz_200Hz,
                     dct4_testinput_q31_50hz_200Hz, 256);
    riscv_float_to_q31(dct4_testinput_f32_50hz_200Hz_ref,
                     dct4_testinput_q31_50hz_200Hz_ref, 256);
    fftSize = 128;

    riscv_cfft_radix4_instance_q31 S;
    // uint8_t ifftFlag = 0, doBitReverse = 1;
    // riscv_cfft_radix4_init_q31(&S, 64, ifftFlag, doBitReverse);

    riscv_rfft_instance_q31 SS;
    // riscv_rfft_init_q31(&SS, fftSize, ifftFlag, doBitReverse);
    riscv_dct4_instance_q31 SSS;
    // riscv_dct4_instance_q31 SSS = {128, 64, 0x10000000, WeightsQ31_128,
    // cos_factorsQ31_128, &SS, &S};
    riscv_dct4_init_q31(&SSS, &SS, &S, 128, 64, 0x10000000);
    BENCH_START(riscv_dct4_q31);
    riscv_dct4_q31(&SSS, q31_state, dct4_testinput_q31_50hz_200Hz);
    BENCH_END(riscv_dct4_q31);
    // riscv_dct4_init_q31(&SSS,&SS,&S,128,64,0x10000000);
    // ref_dct4_q31(&SSS, q31_state, dct4_testinput_q31_50hz_200Hz_ref);
    q31_t resault, resault_ref;
    uint32_t index, index_ref = 5;
    riscv_shift_q31(dct4_testinput_q31_50hz_200Hz, 7,
                  dct4_testinput_q31_50hz_200Hz, fftSize);
    // riscv_shift_q31(dct4_testinput_q31_50hz_200Hz_ref,9,dct4_testinput_q31_50hz_200Hz_ref,fftSize);
    riscv_max_q31(dct4_testinput_q31_50hz_200Hz, 128, &resault, &index);
    // riscv_max_q31(dct4_testinput_q31_50hz_200Hz_ref,128,&resault_ref,&index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_dct4_q31);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_dct4_q31);
}
static int DSP_dct4_q15(void)
{
    uint16_t i;
    /* clang-format off */
    q15_t q15_state[256] = {0};
    float32_t dct4_testinput_f32_50hz_200Hz[256] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559};
    q15_t dct4_testinput_q15_50hz_200Hz[256], dct4_testinput_q15_50hz_200Hz_ref[256];
    /* clang-format on */
    riscv_float_to_q15(dct4_testinput_f32_50hz_200Hz,
                     dct4_testinput_q15_50hz_200Hz, 256);
    riscv_float_to_q15(dct4_testinput_f32_50hz_200Hz,
                     dct4_testinput_q15_50hz_200Hz_ref, 256);
    fftSize = 128;

    riscv_cfft_radix4_instance_q15 S;
    riscv_rfft_instance_q15 SS;
    riscv_dct4_instance_q15 SSS;
    riscv_dct4_init_q15(&SSS, &SS, &S, fftSize, fftSize / 2, 0x1000);
    BENCH_START(riscv_dct4_q15);
    riscv_dct4_q15(&SSS, q15_state, dct4_testinput_q15_50hz_200Hz);
    BENCH_END(riscv_dct4_q15);
    // riscv_dct4_init_q15(&SSS,&SS,&S,fftSize,fftSize/2,0x1000);
    // ref_dct4_q15(&SSS, q15_state, dct4_testinput_q15_50hz_200Hz_ref);
    q15_t resault, resault_ref;
    uint32_t index, index_ref = 5;
    riscv_shift_q15(dct4_testinput_q15_50hz_200Hz, 6,
                  dct4_testinput_q15_50hz_200Hz, fftSize);
    riscv_max_q15(dct4_testinput_q15_50hz_200Hz, fftSize, &resault, &index);
    //  riscv_shift_q15(dct4_testinput_q15_50hz_200Hz_ref,6,dct4_testinput_q15_50hz_200Hz_ref,fftSize);
    // riscv_max_q15(dct4_testinput_q15_50hz_200Hz_ref,fftSize,&resault,&index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_dct4_q15);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_dct4_q15);
}
int main()
{
    BENCH_INIT;
    DSP_dct4_f32();
    DSP_dct4_q31();
    DSP_dct4_q15();
    BENCH_FINISH;
    if (test_flag_error) {
        printf("test error apprears, please recheck.\n");
        return 1;
    } else {
        printf("all test are passed. Well done!\n");
    }
    return 0;
}
